<?php

namespace app\middleware;

use app\common\ApiStatus;
use Webman\MiddlewareInterface;
use Webman\Http\Response;
use Webman\Http\Request;

class ApiAuthCheck implements MiddlewareInterface
{
    public function process(Request $request, callable $next): Response
    {
        $uid = request()->uid;

        if (empty($uid)) {
            $msg = ApiStatus::API_NEED_LOGIN->getStatus();
            return json(['code' => ApiStatus::API_NEED_LOGIN->value, 'msg' => $msg]);
        }
        return $next($request);
    }
}